package com.tpay.client.view;

import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.tpay.client.presenter.ErrorPagePresenter;
import com.tpay.client.uihandlers.ErrorPageUiHandlers;
import com.tpay.client.util.I18nUtil;

public class ErrorPageView extends ViewWithUiHandlers<ErrorPageUiHandlers> implements ErrorPagePresenter.MyView {
	public static final String OK_BUTTON_CONTAINER = "okButtonContainer";

	  private final String html = "<div>\n"
	    + "<table align=\"center\">\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n"
	    + "    <td style=\"font-weight:bold;\">An error has occurred.</td>\n"
	    + "  </tr>\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>Try this action again. If the problem continues,</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>check the application's support forums for a solution or</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>contact the application's administrator.</td>\n" + "</tr>\n"
	    + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
	    + "  <tr>\n"
	    + "    <td id=\"okButtonContainer\"></td>\n"
	    + "  </tr>\n"
	    + "</table>\n"
	    + "</div>\n";

	  private final HTMLPanel panel;
	  private final Button okButton;
	
	public ErrorPageView() {
		panel = new HTMLPanel(html);

	    okButton = new Button(I18nUtil.getConstant().ok());

	    panel.add(okButton, OK_BUTTON_CONTAINER);

	    okButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if(getUiHandlers() != null)
					getUiHandlers().onOkButtonClicked();
			}

	    });
	}
	
	@Override
	public Widget asWidget() {
		return panel;
	}
}
